<!doctype html>
<html>license
<head>
  <meta charset="utf-8">
  <title>从业人员注册信息</title>

  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="format-detection" content="telephone=no, email=no" />


  <link rel="stylesheet" href="../resource/weuimin.css" />
  <link rel="stylesheet" href="../resource/example.css" />

  <link  href="../resource/style.css" rel="stylesheet" type="text/css" />
  <script src="../script/common.js" type="text/javascript" > </script>
  <script src="../resource/html5shivmin.js"></script>
  <script src="../resource/jquery214.js"></script>
  <script src="../resource/fastclick.js"></script>
  <script src="../resource/jqueryweui.js"></script>
  <script src="../resource/zeptomin.js"></script>
  <script src="../resource/picker.js"></script>
  <script src="../resource/pickercity.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script>
    var count =1;
    $.weui = {};
    $.weui.alert = function(options){
      options = $.extend({title: '警告', text: '警告内容'}, options);
      var $alert = $('.weui_dialog_alert');
      $alert.find('.weui_dialog_title').text(options.title);
      $alert.find('.weui_dialog_bd').text(options.text);
      $alert.on('touchend click', '.weui_btn_dialog', function(){
        $alert.hide();
      });
        $alert.show();
    };


    apiready = function () {   
       if(api.systemType == "ios"){
		   document.getElementById("statusBar").style.background = "#298cb4";
		}
       $api.fixStatusBar( $api.dom('header') );
            //事件的激活
       document.getElementById("dw_name").value = $api.getStorage('dw_name');   //自动执行，将登录 人员所属单位名称填入
       document.getElementById("qyid").value = $api.getStorage('dwid');         //自动执行，将登录 人员所属单位ID填入企业ID
       document.getElementById("name").value = $api.getStorage('name');         //自动执行，将登录 人员姓名
       document.getElementById("dw_code").value = $api.getStorage('dw_code');   //自动执行，将登录 人员所属单位代码填入
       document.getElementById("dw_sf").value = $api.getStorage('dw_sf');       //自动执行，将登录 人员所属单位身份填入
	   getMinZu();                                                              //自动 从服务器后台，取得民族数据备用
	   
       $("#filename0").val("人员正面照");                                          //这句其实应该直接写到自身DIV下
      }


    function getPicture(id){               //取得图像或视频，可以从相册、文件、和摄像头中取得
      api.getPicture({
                sourceType: 'camera',        //数据来源，摄像头
                encodingType: 'jpg',         //jpg格式  ，设png无效。。。。
                mediaValue: 'pic',           //媒体是pic图像，也可是视频
                destinationType: 'base64',   //编码
                quality: 100,                //JPG图像的质量
                targetWidth: 400,            //图像 的宽
                targetHeight: 600,           //图像 的高
                saveToPhotoAlbum: false      //是否保存到相册
              },
              function(ret, err) {
                if (ret) {

                  if (ret.data != "") {          //如果返回的数据不为空
                  
                    var ba= ret.base64Data.replace("data:image/jpeg;base64,", "");        //去文件头字符串
                        ba= ba.replace("data:image/jpg;base64,", "");         //去文件头字符串         
                    $("#pic1a").val(ba);         //将图像数据写入#pci1a这个隐藏对象
                    
                  //  console.info('xxxx='+document.getElementById("pic1a").value);
                  //  alert('yyy='+ret.base64Data.substring(0,25));
                    
                    $('#'+ id + '_show').html('');
                    var pic = $('<li class="weui_uploader_file weui_uploader_status" onclick="getPicture(\''+id+'\')"  style="margin-left:5px;width:100px;height:150px;background-image:url(' + ret.base64Data + ')"><div class="weui_uploader_status_content></div></li>');
                    $('#'+ id + '_show').append(pic);    //写入DIV
                    
                    $('#'+ id + '_show').show();         //显示这个图像
                    $('#filename0').hide();              //隐藏 “人员正面照”这个标签
                    $('#'+ id + '_img').hide();
                    $('#'+ id).hide();
                  }
                } else {
                  alert("调用摄像头失败...");
                }
              });
    }








   function chkzjhm(){                    //验证证件号码（身份证），同时取得出生日期  、性别、户籍地区域
        var UUserCard = document.getElementById("zjhm").value;
         //用正则表达式检查身份证号码是否有误！
		     var re = /^\d{6}(((19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\d{3}([0-9]|x|X))|(\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\d{3}))$/;
		 if(!re.test(UUserCard)){
		 alert("身份证号码有误,请重新填写!");
		// location.replace("");
		 return false;
		 }
        else{
              //以下性别判断
		        if (parseInt(UUserCard.substr(16, 1)) % 2 == 1) {
							  //是男则执行代码 ..
							document.getElementById("xb").value = '男';
		         } else {
						   //是女则执行代码 ..
						    document.getElementById("xb").value = '女';
		             }
             //以下出生日期
                var birth=UUserCard.substring(6, 10) + "-" + UUserCard.substring(10, 12) + "-" + UUserCard.substring(12, 14);
                document.getElementById("csrq").value= birth;
            }

    var hjdxzqh=UUserCard.substring(0,6);        //身份证前6位  （户籍地行政区划）
    api.ajax({
		     // url: '/base/syuser!doNotNeedSessionAndSecurity_testmsg1.sy?user='+username+'?password='+password,
		     url: Serverip + '/base/syuser!doNotNeedSessionAndSecurity_getHJDXZQH.sy?hjdxzqh='+hjdxzqh,
		      method: 'get',
		      cache: false,
		      timeout: 30,
		      dataType: 'json'
		  }, function(ret, err){

		 if(ret && ret.ITEM_ID) {
                 document.getElementById("hjdxzqh").value = ret.DISPLAY_NAME;  //写入行政区划
                 document.getElementById("hjdxzqhdm").value = ret.ITEM_ID;     //写入行政区划代码
             }
         else{
               api.alert({
	             title: '行政区划有误！',
	             msg:   '请仔细核对身份证号,如果还有提示错误，请联系单位管理员！'
	             });
                return ;
           }
        });

   }

   function getMinZu(){                   //取得民族和民族编码

               
           api.ajax({
	       url:Serverip + '/base/syuser!doNotNeedSessionAndSecurity_getminzu.sy',
	       method: 'post',
			data: {
				values: {
				}
			}
          },function(data,err){
                var opts = "";
                opts = "<option value=\""+ "请选择" + "\">"+ "请选择" + "</option>";
                for(var i=0;i<data.length;i++){
                  opts += "<option value=\""+ data[i].ITEM_ID + "\">"+ data[i].DISPLAY_NAME + "</option>";
                }
                if(opts != ""){
                   $("#minzutemp").append(opts);
                }

          });
         }


  </script>

  <style>
    .logo-license{margin-top:0px;}
    .left{font-weight:bold;}
    .info {margin-top: 5rem;}
    .btn-1 a {width: 90%;outline: none;border: none;background: #18b4ed;color: #fff;height: 5rem;line-height: 5rem;display: inline-block;border-radius: 0.4rem;font-size: 2rem;}
    .weui_cells_form input, .weui_cells_form label[for], .weui_cells_form textarea {-webkit-tap-highlight-color: rgba(0,0,0,0);}
    .weui_uploader_input {position: absolute;z-index: 1;top: 0;left: 0; width: 100%;height: 100%;opacity: 0;-webkit-tap-highlight-color: rgba(0,0,0,0);}
    .weui_uploader_input_wrp {float: left;position: relative;margin-right: 9px;margin-bottom: 9px;width: 77px;height: 77px;border: 1px solid #d9d9d9;}
    .weui_uploader_files {list-style: none;}
    .weui_uploader_file {font-size: 12px;color: #333;text-align: center;display: table-cell;vertical-align: middle;display: table;}
    .weui_uploader_file {float: left;margin-right: 9px;margin-bottom: 9px;width: 79px; height: 79px;background: no-repeat 50%;background-size: cover;}
    .info ul li .weui_uploader_files{width:99px;height:99px;}
    .js_file_show{display:none;}
    #ssk{background-color:#FFFFFF;width: 93%;height: 5rem;font-size:2rem;}
    /*地址样式*/
    #divselect .all li{line-height:2rem;padding:5px 1rem;text-indent:0;}
    .half > a img {
      width: 11rem;
      height: 8rem;
      margin-left: 0rem;
       margin-top: 0rem;
    }
    .half > a{background:none;}
   .uploader {
    position: absolute;
    width: 54%;
    height: 0 rem;
    left: 32%;
    cursor: default;
    height: 10%;
    float: left;
}          
.filename {
   /* position: absolute;
    outline: 0 none;*/
    line-height: 1.5rem;
    font-size: 1.5rem;
    color: #999;
    width: 60%;
    margin: 0;
    overflow: hidden;
    cursor: default;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 100%;
    top: 9.2rem;
    text-align: center;

}             
    
  </style>

</head>






<body>
<header style="z-index:999" id="statusBar">
  <img onclick="javascript :history.back(-1);" src="../resource/images/rpwbackn.png"/>
  <span>从业人员信息录入</span>
  <div class="clear"></div>
</header>

<div id="loadingToast" style="display:none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast">
        <i class="weui-loading weui-icon_toast"></i>
        <p class="weui-toast__content">数据加载中……</p>
    </div>
</div>

  <form  id="form" method="post" enctype="multipart/form-data">
  <input id="qyid"       name="qyid"       type="hidden" />                    <!--登录单位ID-->
  <input id="hjdxzqhdm"  name="hjdxzqhdm"  type="hidden" />                    <!--户籍地行政区划代码-->
  <input id="minzu"      name="minzu"      type="hidden" />                    <!--民族-->
  <input id="mzdm"       name="mzdm"       type="hidden" />                    <!--民族代码-->
  <input id="name"       name="name"       type="hidden" />                    <!--登录人员姓名-->
  <input id="dw_code"    name="dw_code"    type="hidden" />                    <!--登录单位代码-->
  <input id="dw_sf"      name="dw_sf"      type="hidden" />                    <!--登录单位身份-->
  <input id="pic1a"      name="zpsj"       type="hidden" />                    <!--照片数据-->


  <article class="info">
    <ul>
				<li>
						<div class="left">
							场所名称：
						</div>
						<div class="right">
							<input id="dw_name" name="dw_name"  >
						</div>
						<div class="clear"></div>           <!-- 下方那条横线? -->
					</li>
					<li>
						<div class="left">
							人员姓名：
						</div>
						<div class="right">
							<input id="xm" name="xm" placeholder="请输入从业人员姓名" >
						</div>
						<div class="clear"></div>
					</li>
					<li>
						<div class="left">
							身份证号:
						</div>
						<div class="right">
							<input id="zjhm" name="zjhm" placeholder="请输入身份证号"， onblur="chkzjhm()">
						</div>
						<div class="clear"></div>
					</li>
					<li>
						<div class="left">
							出生日期:
						</div>
						<div class="right">
							<input id="csrq" name="csrq" placeholder="出生日期" readonly="readonly">
						</div>
						<div class="clear"></div>
					</li>
					<li>
						<div class="left">
							性  别:
						</div>
						<div class="right">
							<input id="xb" name="xb" placeholder="性别"   readonly="readonly">
						</div>
						<div class="clear"></div>
					</li>
					<li>
						<div class="left">
							户籍省市:
						</div>
						<div class="right">
							<input id="hjdxzqh" name="hjdxzqh" placeholder="户籍所在省市" readonly="readonly" >
						</div>
						<div class="clear"></div>
					</li>
					<li>
						<div class="left">
							民  族:
						</div>
						<div class="right">
							<!--<input id="minzu" name="minzu" placeholder="请输入民族" onFocus="getMinZu(this.value)" >-->
							<select id="minzutemp" name="minzutemp"></select>
						</div>
						<div class="clear"></div>
					</li>
					<li>
						<div class="left">
							户籍地详址:
						</div>
						<div class="right">
							<input id="hjdxz" name="hjdxz" placeholder="请输入户籍地详址">
						</div>
						<div class="clear"></div>
					</li>
					<li>
						<div class="left">
							现住地址:
						</div>
						<div class="right">
							<input id="zzdz" name="zzdz" placeholder="请输入现住地详址">
						</div>
						<div class="clear"></div>
					</li>
					<li>
						<div class="left">
							联系手机:
						</div>
						<div class="right">
							<input id="shouji" name="shouji" placeholder="请输入联系手机">
						</div>
						<div class="clear"></div>
					</li>
					<li>
						<div class="left">
							联系电话:
						</div>
						<div class="right">
							<input id="lxdh" name="lxdh" placeholder="请输入联系电话">
						</div>
						<div class="clear"></div>
					</li>
					<li>
						<div class="left">
							岗位名称:
						</div>
						<div class="right">
							<input id="gwmc" name="gwmc" placeholder="请输入岗位名称">
						</div>
						<div class="clear"></div>
					</li>
					<li>
						<div class="left">
							入职日期:
						</div>
						<div class="right">
							<!--   <input id="rzrq" name="rzrq" placeholder="请输入入职日期">-->
							<input type="date" id="rzrq" name="rzrq" >
						</div>
						<div class="clear"></div>
					</li>
					<li>
						<div class="left">
							备注:
						</div>
						<div class="right">
							<input id="bz" name="bz" placeholder="请输入备注信息">
						</div>
						<div class="clear"></div>
					</li>


      <li>

	            <div class="uploader">
	              <ul id="pic1_show"  class="weui_uploader_files js_file1_show">
	              </ul>
	              <input type="text" id="filename0" class="filename" readonly/>
	              
                    <a id="pic1_img" class="license js_file1_license" style="margin-top:-9rem;position: absolute !important;" onclick="getPicture('pic1')" >
                    
	                <img id="img-1" src="../resource/images/logon.png"/>    
	              </a>
	              
	             <input id="pic1" type="button" name="pic1" class="js_file1" size="30" />
	            </div>





     			<div class="half" style="float:right;">
     			<a class="logo" id="logox">
				</a>
     			 <p>&nbsp;</p>
			    </div>
				 <div class="clear"></div>
	            
	            
      </li>
      
      
    </ul>
  </article>


  <article class="btn-1">
    <a onclick="ZhuCe()">注   册</a>
  </article>

	</form>
	
</body>

<script>

  function check() {                        //基本信息验证
		    var xm = $api.trimAll(document.getElementById("xm").value);         //从业人员姓名
		    if (xm == null || xm == "") {
		      alert("从业人员姓名不能为空!");
		      return false;
		     }
		    document.getElementById("xm").value=xm;

		    var zjhm = $api.trimAll(document.getElementById("zjhm").value);    //身份证号（证件号码）
		    if(!(/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(zjhm))){
		      alert("请输入正确身份证号!");
		      return false;
		    }
		   document.getElementById("zjhm").value=zjhm;



		    var s=  $("#minzutemp").get(0).selectedIndex;          //取得选择的索引，如果没有选择，s=0
			if(s==0){                                              //判断select是否为空( 如果选择项为0)
		      alert("民族信息不能为空!");
		      return false;
			    }
			document.getElementById("minzu").value=$("#minzutemp").find("option:selected").text();   // 民族汉字
			document.getElementById("mzdm").value=$('#minzutemp option:selected').val();             // 民族代码


		    var hjdxz = $api.trimAll(document.getElementById("hjdxz").value);
		     if (hjdxz == null || hjdxz == "") {
		      alert("户籍地详址不能为空!");
		      return false;
		    }
		    document.getElementById("hjdxz").value=hjdxz;

		    var zzdz = $api.trimAll(document.getElementById("zzdz").value);
		     if (zzdz == null || zzdz == "") {
		      alert("现住地详址不能为空!");
		      return false;
		    }
		     document.getElementById("zzdz").value=zzdz;



		   var shouji = $api.trimAll(document.getElementById("shouji").value);
			  if(shouji == null || shouji == ""){
			      alert("联系手机号不能为空!");
			      return false;
			    }
			  else{
			   if(!(/^1[3|4|5|7|8][0-9]\d{4,8}$/.test(shouji))){     //验证手机号
			      alert("请输入正确手机号");
			      return false;
			     }
			    }
			  document.getElementById("shouji").value=shouji;



		    var lxdh=$api.trimAll(document.getElementById("lxdh").value);         //联系电话
		     if(lxdh==null||lxdh==""){
		     document.getElementById("lxdh").value='空';
		     }
		     else{
//		        var re =/^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/;
//		         if(!re.test(lxdh)){
//		        	      alert("请输入正确联系电话！");
//			      return false;
//		         }
		         document.getElementById("lxdh").value=lxdh;
		       }


		    var gwmc = $api.trimAll(document.getElementById("gwmc").value);    //岗位名称
			     if (gwmc == null || gwmc == "") {
			      alert("岗位名称不能为空!");
			      return false;
			    }
		    document.getElementById("gwmc").value=gwmc;

		//-------------
		    var rzrq = document.getElementById("rzrq").value;           //取入职日期与当前日期对比判断
			   if(rzrq==null||rzrq==""){
			   	      alert("入职日期不能为空!");
				      return false;
			    }
		    var date = new Date();                           //取当前日期
		    var seperator1 = "-";                            //设分割符为-号
		    var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {                 //月份前加0
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {              //日期前加0
		        strDate = "0" + strDate;
		    }
		    var dqrq = date.getFullYear() + seperator1 + month + seperator1 + strDate;    //最终结果日期
		    //以下进行日期比较
		    var arr = rzrq.split("-");
		    var rzrq1 = new Date(arr[0], arr[1], arr[2]);
		    var rzrq2 = rzrq1.getTime();
		    var arrs = dqrq.split("-");
		    var dqrq1 = new Date(arrs[0], arrs[1], arrs[2]);
		    var dqrq2 = dqrq1.getTime();

		    if (rzrq2 > dqrq1) {
			    alert("入职日期晚于当前日期！请重新选择……");
		        return false;
		       }
		//-----------------------------
		    var bz=$api.trimAll(document.getElementById("bz").value);         //备注信息
		     if(bz==null||bz==""){
		     document.getElementById("bz").value='空';
		     }
		     document.getElementById("bz").value=bz;


			if(document.getElementById("pic1a").value==null||document.getElementById("pic1a").value==""){     //照片数据验证
			       alert("请上传从业人员正面照片！");
			       return false;
			     }


	    return true;        //如果以上都 通过，返回T
	  }




  function ZhuCe() {                                     //提交注册

		 var a = check();              //进行表单检验
		 if(a){
				$("#loadingToast").show();
				api.ajax({ 
		            url: Serverip + '/base/syuser!doNotNeedSessionAndSecurity_SaveCRYY.sy',
		            method: 'post',
					dataType: 'json',
		            data: { 
					            values:{
					            
								    qyid:document.getElementById("qyid").value,
								    hjdxzqhdm:document.getElementById("hjdxzqhdm").value,					          
								    minzu:document.getElementById("minzu").value,					          
								    mzdm:document.getElementById("mzdm").value,					          
								    name:document.getElementById("name").value,
								    dw_code:document.getElementById("dw_code").value,					          
								    dw_sf:document.getElementById("dw_sf").value,	
								    zpsj:document.getElementById("pic1a").value,       //.....照片	
								 
								 	dw_name:document.getElementById("dw_name").value,
								    xm:document.getElementById("xm").value,
								    zjhm:document.getElementById("zjhm").value,	
								    csrq:document.getElementById("csrq").value,
								    xb:document.getElementById("xb").value,
								    hjdxzqh:document.getElementById("hjdxzqh").value,	
								    hjdxz:document.getElementById("hjdxz").value,								    							    
								    zzdz:document.getElementById("zzdz").value,
								    shouji:document.getElementById("shouji").value,								    							    
								    lxdh:document.getElementById("lxdh").value,								
								    gwmc:document.getElementById("gwmc").value,								    							    
								    rzrq:document.getElementById("rzrq").value,	
								    bz:document.getElementById("bz").value								    							    
    
								       }, 

			
                          },
		            timeout: 30,
                  }, function(ret, err) { 
				    if (ret) {
				                $("#loadingToast").hide();
				        
				        		 switch(ret.returninfo){ 

						              case 0:
								              alert("注册成功!");
							                  location.href='cadmin.html';
							                  document.getElementById("xm").value=null;
							                  document.getElementById("zjhm").value=null;
						 	                  break;
					
						              case 1:
							                 alert("注册失败!该人员在其它场所已注册且尚未离职，请与场所系统管理员联系！");
							                 break;
					
							          case 2:
							                 alert("注册失败!请与场所系统管理员联系！");
							                 break;
							                }
				        
				    }else {
				         $("#loadingToast").hide();
                         api.alert({msg:('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode)}); 
				           };

                 });	

		     }//end if 


        } //end 注册上传

</script>


</html>
